home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 27 / develop issue 27 code / speech recognition.frameworks / cdocdemo w. speech / cdocdemoapp.cp next >
Encoding:
Text File  |  1996-05-31  |  5.9 KB  |  212 lines

  1. // ===========================================================================
  2. //    CDocDemoApp.cp                    ©1994 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    A simple Application class which manages text documents.
  6.  
  7. #include <StandardFile.h>
  8.  
  9. #include <LApplication.h>
  10. #include <LGrowZone.h>
  11. #include <LWindow.h>
  12. #include <LScroller.h>
  13. #include <LPrintout.h>
  14. #include <LPlaceHolder.h>
  15.  
  16. #include <UMemoryMgr.h>
  17. #include <UDrawingState.h>
  18. #include <URegistrar.h>
  19. #include <UDesktop.h>
  20.  
  21. #include "CDocDemoApp.h"
  22. #include "CTextDoc.h"
  23. #include "CDirtyText.h"
  24.  
  25. // the following is added for speech recognition
  26. #include "CDocSpeech.h"
  27. extern CDocSpeech    *gDocSpeechObj;
  28. Boolean                gHasSpeechRecog;
  29.  
  30.  
  31. // ===========================================================================
  32. //        • Main Program
  33. // ===========================================================================
  34.  
  35. void main(void)
  36. {
  37.                                     // Set Debugging options
  38.     SetDebugThrow_(debugAction_Alert);
  39.     SetDebugSignal_(debugAction_Alert);
  40.  
  41.     InitializeHeap(3);                // Initialize Memory Manager
  42.                                     // Parameter is number of Master Pointer
  43.                                     //   blocks to allocate
  44.     
  45.                                     // Initialize standard Toolbox managers
  46.     UQDGlobals::InitializeToolbox(&qd);    
  47.     
  48.     new LGrowZone(20000);            // Install a GrowZone function to catch
  49.                                     //    low memory situations.
  50.                                     //    Parameter is size of reserve memory
  51.                                     //    block to allocated. The first time
  52.                                     //    the GrowZone function is called,
  53.                                     //    there will be at least this much
  54.                                     //    memory left (so you'll have enough
  55.                                     //    memory to alert the user or finish
  56.                                     //    what you are doing).
  57.     
  58.     CDocDemoApp    theApp;                // Create instance of your Application
  59.     theApp.Run();                    //   class and run it
  60. }
  61.  
  62.  
  63. // ===========================================================================
  64. //        • CDocDemoApp Class
  65. // ===========================================================================
  66.  
  67. // ---------------------------------------------------------------------------
  68. //        • CDocDemoApp
  69. // ---------------------------------------------------------------------------
  70. //    Constructor
  71.  
  72. CDocDemoApp::CDocDemoApp()
  73. {
  74.         // Register classes for objects created from 'PPob' resources
  75.     URegistrar::RegisterClass(LWindow::class_ID,        (ClassCreatorFunc) LWindow::CreateWindowStream);
  76.     URegistrar::RegisterClass(LScroller::class_ID,        (ClassCreatorFunc) LScroller::CreateScrollerStream);
  77.     URegistrar::RegisterClass(LPlaceHolder::class_ID,    (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
  78.     URegistrar::RegisterClass(LPrintout::class_ID,        (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
  79.     URegistrar::RegisterClass(LView::class_ID,            (ClassCreatorFunc) LView::CreateViewStream);
  80.  
  81.     URegistrar::RegisterClass('Dtxt', (ClassCreatorFunc) CDirtyText::CreateDirtyTextStream);
  82.     
  83.     //determine if Speech Recognition Manager is available;
  84.     //if it is available, create a custom speech recognition object (CDocSpeech)
  85.     long    theAttrs;    
  86.     OSErr    theErr;
  87.     
  88.     gHasSpeechRecog = false;
  89.     theErr = ::Gestalt(gestaltSpeechRecognitionVersion, &theAttrs);
  90.     //version must be at least 1.5.0 to support SRM API used here
  91.     if (!theErr)
  92.         if (theAttrs >= 0x00000150) {
  93.             gHasSpeechRecog = true;
  94.             gDocSpeechObj = new CDocSpeech();    //create a single instance of the CDocSpeech class        
  95.         }
  96. }
  97.  
  98.  
  99. // ---------------------------------------------------------------------------
  100. //        • ~CDocDemoApp
  101. // ---------------------------------------------------------------------------
  102. //    Destructor
  103.  
  104. CDocDemoApp::~CDocDemoApp()
  105. {
  106.     //shut down speech recognition, if it's running
  107.     if (gHasSpeechRecog) {
  108.         delete gDocSpeechObj;
  109.     }
  110. }
  111.  
  112.  
  113. // ---------------------------------------------------------------------------
  114. //        • ObeyCommand
  115. // ---------------------------------------------------------------------------
  116. //    Respond to commands
  117.  
  118. Boolean
  119. CDocDemoApp::ObeyCommand(
  120.     CommandT    inCommand,
  121.     void        *ioParam)
  122. {
  123.     Boolean    cmdHandled = true;
  124.     
  125.     switch (inCommand) {
  126.     
  127.         // +++ Add cases here for the commands you handle
  128.         //        Remember to add same cases to FindCommandStatus below
  129.         //        to enable/disable the menu items for the commands
  130.     
  131.         default:
  132.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  133.             break;
  134.     }
  135.     
  136.     return cmdHandled;
  137. }
  138.  
  139.  
  140. // ---------------------------------------------------------------------------
  141. //        • FindCommandStatus
  142. // ---------------------------------------------------------------------------
  143. //    Pass back status of a (menu) command
  144.  
  145. void
  146. CDocDemoApp::FindCommandStatus(
  147.     CommandT    inCommand,
  148.     Boolean        &outEnabled,
  149.     Boolean        &outUsesMark,
  150.     Char16        &outMark,
  151.     Str255        outName)
  152. {
  153.     outUsesMark = false;
  154.     
  155.     switch (inCommand) {
  156.     
  157.         // +++ Add cases here for the commands you handle
  158.     
  159.         default:
  160.             LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  161.                                 outMark, outName);
  162.             break;
  163.     }
  164. }
  165.  
  166.  
  167. // ---------------------------------------------------------------------------
  168. //        • OpenDocument
  169. // ---------------------------------------------------------------------------
  170. //    Open a Document file
  171.  
  172. void
  173. CDocDemoApp::OpenDocument(
  174.     FSSpec    *inMacFSSpec)
  175. {
  176.     CTextDoc    *theDoc = new CTextDoc(this, inMacFSSpec);
  177. }
  178.  
  179.  
  180. // ---------------------------------------------------------------------------
  181. //        • MakeNewDocument
  182. // ---------------------------------------------------------------------------
  183. //    Create a new Document
  184.  
  185. LModelObject*
  186. CDocDemoApp::MakeNewDocument()
  187. {
  188.     CTextDoc    *theDoc = new CTextDoc(this, nil);
  189.     return theDoc;
  190. }
  191.  
  192.  
  193. // ---------------------------------------------------------------------------
  194. //        • ChooseDocument
  195. // ---------------------------------------------------------------------------
  196. //    Prompt the user to select a document to open
  197.  
  198. void
  199. CDocDemoApp::ChooseDocument()
  200. {
  201.     StandardFileReply    macFileReply;
  202.     SFTypeList            typeList;
  203.     
  204.     UDesktop::Deactivate();
  205.     typeList[0] = 'TEXT';
  206.     ::StandardGetFile(nil, 1, typeList, &macFileReply);
  207.     UDesktop::Activate();
  208.     if (macFileReply.sfGood) {
  209.         OpenDocument(&macFileReply.sfFile);
  210.     }
  211. }
  212.